package com.allwees.core.event.annotation;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;
import org.springframework.util.Assert;

@Getter
@Setter
@ToString
public class LocalEventOperation {

    private final Class<? extends ApplicationEvent> event;

    private final String source;

    private final String condition;

    public LocalEventOperation(Builder b) {
        this.event = b.event;
        this.source = b.source;
        this.condition = b.condition;
    }

    @Getter
    public static class Builder {

        private Class<? extends ApplicationEvent> event;

        private String source;

        private String condition;

        public void setEvent(Class<? extends ApplicationEvent> event) {
            Assert.notNull(event, "Event name must not be null");
            this.event = event;
        }

        public void setCondition(String condition) {
            this.condition = condition;
        }

        public void setSource(String source) {
            Assert.notNull(source, "Event source must not be null");
            this.source = source;
        }

        public LocalEventOperation build() {
            return new LocalEventOperation(this);
        }
    }
}
